package com.example.tests;

import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.*;

import java.util.Random;
import org.testng.annotations.Test;
import com.example.utils.SortedListOf;

public class GroupModificationTests extends TestBase {
	
	@Test(dataProvider = "randomValidGroupGenerator")
	public void modifySomeGroup(GroupData group) {
		// save old  groups
		SortedListOf<GroupData> oldContacts = app.getGroupHelper().getGroups();
		
		Random rnd = new Random();
		int index = rnd.nextInt(oldContacts.size());
		
		// actions
		app.getGroupHelper().modifyGroup(index, group);
		
		// save new groups
		SortedListOf<GroupData> newContacts = app.getGroupHelper().getGroups();
		
		// comparing		
		assertThat(newContacts, equalTo(oldContacts.without(index).withAdded(group)));
	}
	
	@Test(dataProvider = "invalidGroupGenerator")
	public void unsuccessfulModifySomeGroup(GroupData group) {
		// save old  groups
		SortedListOf<GroupData> oldList = app.getGroupHelper().getGroups();
		
		Random rnd = new Random();
		int index = rnd.nextInt(oldList.size()-1);
		
		// actions
		app.getGroupHelper().modifyGroup(index, group);
		
		// save new groups
		SortedListOf<GroupData> newList = app.getGroupHelper().getGroups();
		
		// comparing		
		assertThat(oldList, equalTo(newList));
	}
}
